package net.service.Impl;

import net.mapper.CommentsMapper;
import net.mapper.UserMapper;
import net.pojo.Comments;
import net.pojo.User;
import net.service.CommentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author admin
 * @Date 2019/5/28 8:40
 */
@Service
@Transactional
public class CommentsServiceImpl implements CommentsService {
    @Autowired
    CommentsMapper commentsMapper;
    @Autowired
    UserMapper userMapper;
    @Override
    public List<Comments> findPageByUid(Integer usid) {
        List<Comments> list = commentsMapper.findPageByUid(usid);
        for (Comments comments : list){
            User user = userMapper.findById(comments.getUsid());
            comments.setUser(user);
        }
        return list;
    }

    @Override
    public List<Comments> findAll() {
        return commentsMapper.findAll();
    }

    @Override
    public List<Comments> findByCtime() {
        List<Comments> list = commentsMapper.findByCtime();
        for (Comments comments : list){
            User user = userMapper.findById(comments.getUsid());
            comments.setUser(user);
        }
        return list;
    }

    @Override
    public int addComments(Comments comments) {
        return commentsMapper.addComments(comments);
    }
}
